package com.nutricia.core.service.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import com.nutricia.common.api.result.QueryMyMeeting;
import com.nutricia.core.ex.BizErrorCode;
import com.nutricia.core.ex.BizException;
import com.nutricia.core.model.domain.MeetingDO;
import com.nutricia.core.service.MainInterfaceService;

/**
 * 主界面service的实现类
* @author wangzl
* @date 2018年5月7日
 */
@Service("mainInterfaceService")
public class MainInterfaceServiceImpl extends AbstractServiceImpl implements MainInterfaceService{
	@Override
	public List<QueryMyMeeting> queryMyMeetingById(String founderId) {
		logger.info("根据用户ID查询我创建的会议开始！");
		List<QueryMyMeeting> queryMyMeetingList = new ArrayList<QueryMyMeeting>();
		try {
			//查询我创建的所有会议
			List<MeetingDO> meetingLists = mainIntrfaceMapper.queryMyMeetingById(founderId);
			//日期格式转换成字符串
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	    	for(MeetingDO meetingDO : meetingLists) {
	    		QueryMyMeeting qmmr = new QueryMyMeeting();
	    		qmmr.setmId(meetingDO.getmId());
	    		qmmr.setmName(meetingDO.getmName());
	    		qmmr.setmStartDate(sdf.format(meetingDO.getmStartDate()).toString());
	    		qmmr.setmEndDate(sdf.format(meetingDO.getmEndDate()).toString());
	    		qmmr.setmHostCity(meetingDO.getmHostCity());
	    		qmmr.setmNatures(meetingDO.getmNatures());
	    		queryMyMeetingList.add(qmmr);
	    	}
	    	
		} catch (Exception e) {
			logger.error("根据用户ID查询我创建的会议异常：{MainInterfaceServiceImpl.queryMyMeetingById}", e);
	        throw new BizException(BizErrorCode.SYSTEM_ERROR, "系统异常");
		}
		logger.info("根据用户ID查询我创建的会议成功！");
		return queryMyMeetingList;
	}
}
